package com.loklok.code.confuse.converter;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.intellij.util.xmlb.Converter;
import com.loklok.code.confuse.model.CodePathConfig;
import com.loklok.code.confuse.model.FeignInterfaceInfo;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

/**
 * @Classname FeignInterfaceInfoConverter
 * @Description
 * @Date 2023/5/15 20:34
 * @author by wangchangjiu
 */
public class FeignInterfaceInfoConverter extends Converter<Map<String, FeignInterfaceInfo>> {

    @Override
    public @Nullable Map<String, FeignInterfaceInfo> fromString(@NotNull String value) {
        Gson gson = new Gson();
        // 修改此处的反序列化目标类型为正确的 Map 类型
        return gson.fromJson(value, new TypeToken<Map<String, FeignInterfaceInfo>>(){}.getType());
    }

    @Override
    public @Nullable String toString(@NotNull Map<String, FeignInterfaceInfo> value) {
        Gson gson = new Gson();
        // 使用正确的类型进行序列化
        return gson.toJson(value);
    }
}
